package com.demo.demo01.controller;

import com.demo.demo01.mapper.UserMapper;
import com.demo.demo01.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class UserController {

    @Autowired
    private UserMapper userMapper;

    @GetMapping("/queryUserList")
    public List<User> queryUserList(){
        List<User> userList = userMapper.queryUserList();
        System.out.println(userList);
        return userList;
    }

    @GetMapping("/queryUserByID")
    public User queryUserByID(String account){
        User user = userMapper.queryUserByID(account);
        System.out.println(user);
        return user;
    }

    @GetMapping("/addUser")
    public int addUser(User user) {
        int result = userMapper.addUser(user);
        return result;
    }

    @RequestMapping("/login")
    public User userLogin(String account, String password){
        User user = userMapper.queryUserByID(account);
        System.out.println(account + " " + password + " " + user.getPassword());
        System.out.println(user);
        return password.equals(user.getPassword())?user:null;
    }

}
